package com.yunsc.store.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.yunsc.common.serializer.TimestampToDateSerializer;
import com.yunsc.product.vo.GoodsInfoVO;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 购物车记录表
 * 
 * @author adan
 * @email 2028038953@qq.com
 * @date 2024-04-22 11:35:52
 */
@Data
@TableName("yunsc_cart")
public class YunscCartEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 主键ID
	 */
	@TableId
	private Integer id;
	/**
	 * 商品ID
	 */
	private Integer goodsId;
	/**
	 * 商品sku唯一标识
	 */
	private String goodsSkuId;
	/**
	 * 商品数量
	 */
	private Integer goodsNum;
	/**
	 * 用户ID
	 */
	private Integer userId;
	/**
	 * 是否删除
	 */
	private Integer isDelete;
	/**
	 * 商城ID
	 */
	private Integer storeId;
	/**
	 * 创建时间
	 */
	@TableField(fill = FieldFill.INSERT)
	@JsonSerialize(using = TimestampToDateSerializer.class)
	private Integer createTime;
	/**
	 * 更新时间
	 */
	@TableField(fill = FieldFill.INSERT_UPDATE)
	@JsonSerialize(using = TimestampToDateSerializer.class)
	private Integer updateTime;

	@TableField(exist = false)
	private GoodsInfoVO goods;

	public static void main(String[] args) {
		// 假设当前月份值为 currentMonthValue，上四个月份值为 fourMonthsAgoValue
		BigDecimal currentMonthValue = new BigDecimal("101");
		BigDecimal fourMonthsAgoValue = new BigDecimal("100");

		// 计算涨幅
		BigDecimal diff = currentMonthValue.subtract(fourMonthsAgoValue);
		BigDecimal increase;

		if (fourMonthsAgoValue.compareTo(BigDecimal.ZERO) != 0) {
			increase = diff.divide(fourMonthsAgoValue, 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
			System.out.println("涨幅为：" + increase + "%");
		} else {
			System.out.println("上四个月份的值为 0，无法计算涨幅");
		}
	}
}
